package routers

import (
	"github.com/gin-gonic/gin"
	"hass.tree.com/bridge/auth"
	"hass.tree.com/bridge/model"
	"hass.tree.com/bridge/vo"
)

func LoadMember(e *gin.Engine) {
	memberRoute := e.Group("/member")
	{
		memberRoute.Use(auth.JWTauth())
		memberRoute.POST("/list", memberList)
		memberRoute.POST("/page", memberPage)
	}

}
func memberList(c *gin.Context) {
	members := model.FindAllMember()
	vo.Success(members, c)
}

func memberPage(c *gin.Context) {

	var pageRequest vo.PageRequest
	if err := c.ShouldBindJSON(&pageRequest); err != nil {
		vo.Fail(err.Error(), c)
		return
	}

	members := model.PageMember(pageRequest.Page, pageRequest.Size)
	vo.Success(members, c)
}
